package eventplanner.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.net.MalformedURLException;

public class URLValidator implements ConstraintValidator<URL, String> {

	@Override
	public void initialize(URL constraintAnnotation) {

	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if (value == null || value.trim().isEmpty()) {
			return true;
		} else {
			try {
				new java.net.URL(value);
				return true;
			} catch (MalformedURLException e) {
				return false;
			}
		}
	}
}
